﻿#ifndef _TES_QUATERNION_H_
#define _TES_QUATERNION_H_

#include <math.h>

#ifndef PAI
#define PAI 3.1415926585f
#endif

class TesEular;
class TesVector3;
class TesMatrix3x3;
class TesQuaternion  //角度参数是弧度值
{
public:

	float x, y, z, w;

	TesQuaternion()
	{
		Identity();
	}

	//单位四元数
	void Identity();

	//标准化
	void Normalize();

	//模场
	float Length();

	//旋转
	void RotateX(float degree);
	void RotateY(float degree);
	void RotateZ(float degree);
	void RotateAxis(float degree, const TesVector3& Axis);

	//叉乘相关
	TesQuaternion operator * (const TesQuaternion& that);
	TesQuaternion& operator *= (const TesQuaternion& that);
	TesQuaternion operator * (float k);
	TesQuaternion& operator *= (float k);

	//向量乘四元数
	TesVector3 operator* (const TesVector3& N);

	//点乘
	float DotProduct(const TesQuaternion& that) const;

	//共轭
	TesQuaternion Conjugate();

	//逆
	TesQuaternion Inverse();

	//求两个四元数之间的差值
	TesQuaternion operator -(const TesQuaternion& that); 

	//求幂
	TesQuaternion Pow(float t);

	//获取矩阵
	TesMatrix3x3 Matrix3x3();

	//从欧拉角初始化旋转
	void FromEuler(const TesEular& orientation);

	//转换到欧拉角
	void ToEuler(TesEular& euler);

	//旋转角度和轴获取
	float GetRotationAngleRedius();
  	float GetRotationAngleDegree();
	TesVector3 GetRotationAxis();
};

float DotProduct(const TesQuaternion& a, const TesQuaternion& b);

TesQuaternion operator *(float k, TesQuaternion q);
TesVector3 operator* (const TesVector3& N, TesQuaternion q);

TesQuaternion Slerp(TesQuaternion& q0, TesQuaternion& q1, float t); //t在0-1之间
	

#endif